using DOTS.DOD.LESSON0;
using Unity.Burst;
using Unity.Entities;
using Unity.Transforms;

namespace DOTS.DOD.LESSON1
{
    [UpdateInGroup(typeof(RotateCubesFilterSystemGroup))]
    [BurstCompile]
    public partial struct GreenCubeRotateSystem : ISystem
    {
        [BurstCompile]
        public void OnUpdate(ref SystemState state)
        {
            float deltaTime = SystemAPI.Time.DeltaTime;
            //SystemAPI.Query<>方法只能找到并集，不能找补集
            //只能在主线程调用
            foreach (var (transform, speed, tag) in SystemAPI
                .Query<RefRW<LocalTransform>, RefRO<RotateSpeed>, RefRO<GreenCubeTag>>())
            {
                transform.ValueRW = transform.ValueRO.RotateY(deltaTime * speed.ValueRO.Value);
            }
        }
    }
}